package com.jh3502.helper.function.bluetooth;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.jh3502.helper.R;
import com.vise.baseble.model.BluetoothLeDevice;
import com.vise.xsnow.ui.adapter.helper.HelperAdapter;
import com.vise.xsnow.ui.adapter.helper.HelperViewHolder;

public class BlueToothListAdapter extends HelperAdapter<BluetoothLeDevice> {

    public BlueToothListAdapter(Context context) {
        super(context, R.layout.item_blue_tooth_list);
    }

    @Override
    public void HelpConvert(@NonNull HelperViewHolder viewHolder, int position, @Nullable BluetoothLeDevice bluetoothLeDevice) {
        TextView item_blue_tooth_name = viewHolder.getView(R.id.item_blue_tooth_name);
        TextView item_blue_tooth_mac = viewHolder.getView(R.id.item_blue_tooth_mac);
        TextView item_blue_tooth_rssi = viewHolder.getView(R.id.item_blue_tooth_rssi);
        if (bluetoothLeDevice != null && bluetoothLeDevice.getDevice() != null) {
            String deviceName = bluetoothLeDevice.getDevice().getName();
            if (deviceName != null && !deviceName.isEmpty()) {
                item_blue_tooth_name.setText(deviceName);
            } else {
                item_blue_tooth_name.setText("未知设备");
            }
            item_blue_tooth_mac.setText(bluetoothLeDevice.getDevice().getAddress());
            item_blue_tooth_rssi.setText(bluetoothLeDevice.getRssi() + "dB");
        }
    }
}
